<template>
  <el-dialog title="打印" :visible.sync="openOne" width="800px" append-to-body :before-close="close">
    <!--    <el-input :model="value1" placeholder="请输入需要生成的内容" clearable @input="aaa" />-->

    <div v-if="list" id="printMe" class="main1">

      <div class="title">
        <img ref="qrCodeDiv" style="float: left;width: 300px;">
        <p class="zi1">{{ list.company }}</p>
      </div>
      <div style="float:left;width:555px;">
        <p class="title2">INBOUND TALLY SHEET</p>
      </div>
      <div class="area">
        <div class="column">
          <p class="zi1">入库编号:</p>
          <p class="zi2">{{ list.warehousing_id }}</p>
        </div>
        <div class="column column2">
          <p class="zi1">项目:</p>
          <p class="zi2">{{ list.project_id_name }}</p>
        </div>
        <div class="column">
          <p class="zi1">委托方:</p>
          <p class="zi2">{{ list.project_client_name }}</p>
        </div>
        <div class="column column2">
          <p class="zi1">客户订单类型:</p>
          <p class="zi2">{{ list.customer_order_type }}</p>
        </div>
        <div class="column">
          <p class="zi1">结算方:</p>
          <p class="zi2">{{ list.settlement }}</p>
        </div>
        <div class="column column2">
          <p class="zi1">客户业务单号:</p>
          <p class="zi2">{{ list.customer_business_number }}</p>
        </div>
        <div class="column">
          <p class="zi1">商品总数量:</p>
          <p class="zi2">{{ list.goods_number }}</p>
        </div>
        <div class="column column2">
          <p class="zi1">实际入库数量:</p>
          <p class="zi2">{{ list.actual_number }}</p>
        </div>
      </div>
      <div v-if="list.stock" class="form">
        <table class="collapsed">
          <thead>
            <tr>
              <th>料号</th>
              <th>包装</th>
              <th>托盘码</th>
              <th>库位</th>
              <th>入库数量</th>
              <th>入库箱数</th>
              <th>货物状态</th>
            </tr>
          </thead>
          <tbody>
            <template v-for="(itme,index) in list.stock">
              <tr :key="index">
                <td>{{ itme.goods_name }}</td>
                <td>{{ itme.packing_num }} / {{ itme.unit_name }}</td>
                <td>{{ itme.tray_id }}</td>
                <td>{{ itme.config_name }}</td>
                <td>{{ itme.number }}</td>
                <td>{{ itme.box_number }}</td>
                <td>{{ itme.goods_status }}</td>
              </tr>

              <tr :key="`tr_2_${index}`">
                <td colspan="3">
                  <img :ref="`${itme.refName1}`">
                </td>
                <td colspan="4">
                  <img :ref="`${itme.refName2}`">
                </td>
              </tr>
            </template>

            <!--            <tr v-for="(item,index) in list.stock">-->
            <!--              <td style="height: 35px;" />-->
            <!--              <td style="height: 35px;" />-->
            <!--              <td style="height: 35px;" />-->
            <!--              <td style="height: 35px;" />-->
            <!--              <td style="height: 35px;" />-->
            <!--              <td style="height: 35px;" />-->
            <!--            </tr>-->
          </tbody>
        </table>
      </div>
      <!--      <hr style="float:left;width:555px;margin-top:5px;">-->
      <div class="tail" style="margin-top: 10px;">
        <div class="nr1">
          <p class="zi1">创建人:</p>
          <p class="zi2">{{ list.username }}</p>
        </div>
        <div class="nr1">
          <p class="zi1">创建时间:{{ list.created_at }}</p>
          <p class="zi2" />
        </div>
        <!--        <div class="nr1">-->
        <!--          <p class="zi1">收货人:</p>-->
        <!--          <p class="zi2" />-->
        <!--        </div>-->
        <!--        <div class="nr1">-->
        <!--          <p class="zi1">收货时间:</p>-->
        <!--          <p class="zi2" />-->
        <!--        </div>-->
      </div>
    </div>
    <el-row style="top: 30px;margin-bottom: 30px;text-align:center;">
      <el-col :span="24">
        <el-button v-print="'#printMe'" type="primary" size="medium">打印</el-button>
      </el-col>
    </el-row>
  </el-dialog>
</template>
<script>
import { warehousingPrint } from '@/api/storehouse'
import JsBarcode from 'jsbarcode'
export default {
  name: 'Print',
  components: {
  },
  props: {
    openOne: {
      type: Boolean
    },
    warehousing_id: {
      type: String
    },
    warehousing_son_id: {
      type: String
    }
  },
  data() {
    return {
      value1: '',
      list: []
    }
  },
  watch: {
    'openOne': function(newValue, oldValue) {
      if (newValue === true) {
        this.printList()
      }
    }
  },
  created() {

  },
  methods: {

    printList() {
      const that = this
      const data = {
        warehousing_id: this.warehousing_id,
        warehousing_son_id: this.warehousing_son_id
      }
      warehousingPrint(data).then(response => {
        if (response.code === 10000) {
          that.list = response.data

          that.list.stock.forEach(item => {
            item.refName1 = item.id + '_g'
            item.refName2 = item.id + '_n'
          })
          console.log(that.list)

          that.$nextTick(function() {
            that.list.stock.forEach(item => {
              JsBarcode(that.$refs[item.refName1], item.goods_name, {
                format: 'CODE128', // 条形码的格式
                width: 2, // 线宽
                height: 26, // 条码高度
                lineColor: '#000', // 线条颜色
                displayValue: true, // 是否显示文字
                margin: 2 // 设置条形码周围的空白区域
              })

              JsBarcode(that.$refs[item.refName2], item.number, {
                format: 'CODE128', // 条形码的格式
                width: 2, // 线宽
                height: 26, // 条码高度
                lineColor: '#000', // 线条颜色
                displayValue: true, // 是否显示文字
                margin: 2 // 设置条形码周围的空白区域
              })
            })
          })

          JsBarcode(this.$refs.qrCodeDiv, that.list.warehousing_id, {
            format: 'CODE128', // 条形码的格式
            width: 2, // 线宽
            height: 26, // 条码高度
            lineColor: '#000', // 线条颜色
            displayValue: true, // 是否显示文字
            margin: 2 // 设置条形码周围的空白区域
          })
        }
      })
    },
    close() {
      this.$emit('update:openOne', false)
    }
  }
}
</script>
<style lang="scss" scoped>
img {
    width: 100%;
    float: left;
}

p {
    padding: 0;
    margin: 0;
    font-family: 宋体
}

div {
    font-family: 宋体;
}

.main1 {
    width: 555px;
    background: #fff;
    padding: 0px 20px;
    margin:auto;
}

.title {
    float: left;
    width: 555px;
    border-bottom: 2px solid #000;
    padding: 10px 0px;
}

.title .logo {
    float: left;
    width: 116px;
    height: 30px;
}

.title .zi1 {
    float:right;
    line-height: 30px;
    font-size: 18px;
    color: #000;
}
.title .zi2 {
    float:right;
    line-height: 30px;
    font-size: 14px;
    color: #999;
    width:555px;
    text-align:right;
}

.title2 {
    float: left;
    line-height: 40px;
    font-size: 18px;
    color: #970000;
}

.title2-1 {
    float:right;
    height: 40px;
    width:200px;
}

.area {
    float: left;
    width: 555px;
}

.area p {
    font-size: 11px;
    line-height: 24px;
}

.area .column {
    float: left;
    width: 272.5px;
    margin-right: 10px;
    margin-bottom: 5px;
}

.area .column .img1{float:left;width:200px;height:40px;margin-left:10px;}

.area .column2 {
    margin-right: 0;
}

.area .zi1 {
    float: left;
    border-bottom: 1px solid #fff;
    width: 100px;
}

.area .zi2 {
    float: left;
    //border-bottom: 1px solid #000;
    width: 160.5px;
    margin-left: 10px;
}

.form {
    float: left;
    width: 555px;
    margin-top: 10px;
}

.form .name {
    float: left;
    width: 555px;
    font-size: 14px;
    line-height:30px;
}

table,
td,
th {
    padding: 3px;
    border: 1px solid #aaa;
    text-align: center;
    font-size: 12px;
    line-height: 18px;
}

th {
    font-weight: bold;
}

.separate {
    border-collapse: separate;
}

.collapsed {
    border-collapse: collapse;
    width: 555px;
}

.tail {
    float: left;
    width: 555px;
    margin-top: 5px;
    margin-bottom: 20px;
}

.tail .nr1 {
    float: left;
    width: 277.5px;
    font-size: 10px;
    line-height: 18px;
}

.tail .nr1 p {
    float: left;
}

.tail .nr1 .zi2 {
    margin-left: 5px;
}
</style>

